Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This is a component for Linuxcnc HAL
- // Copyright 2020 Sam Sokolik <samcoinc@gmail.com>
- //
- // This program is free software; you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation; either version 2 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program; if not, write to the Free Software
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- component polygon "Create a spindle synced motion that carves a polygon using eoffset inputs";
- pin in unsigned numsides=3 "Number of sides in the polygon";
- pin in float inscribedradius=1 "inscribed radius of the polygon";
- pin in float cutterdiam "cutter diameter";
- pin in float eoffsetscale "scale that eoffset is set to.";
- pin in float spindlepos "Spindle position scaled to 1 per rev";
- pin out float spindlerad "Spindle postion in radians";
- pin out float polyradius "radious of the polygon at given spindle position";
- pin out float xoffset "x offset to send to offset componant";
- pin out float yoffset "y offset to send to the offset componant";
- pin out signed xeoffset "x eoffset output";
- pin out signed yeoffset "y eoffset output";
- function _;
- license "GPL";
- ;;
- #include <rtapi_math.h>
- #define PI 3.14159265358979323846
- float spinang;
- float scale;
- //formual I found is for circumscribed - convert to inscribed - makes more sense.
- scale=inscribedradius/cos(PI/numsides);
- spinang = (spindlepos - (int)(spindlepos))*2*PI;
- polyradius = (cos(PI/numsides)/cos((fmod(spinang, (2*PI/numsides))-PI/numsides)))*scale-cutterdiam;
- xoffset = cos(spinang)*polyradius;
- yoffset = sin(spinang)*polyradius;
- xeoffset = xoffset * eoffsetscale;
- yeoffset = yoffset * eoffsetscale;
- spindlerad = spinang;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement